<?php

namespace pUtils;

use Redis;

class rds {
    
    private Redis $conn;
    
    /**
     * rds constructor.
     * @param string|null $rds
     */
    function __construct(string $rds = null) {
        list($host, $port, $password) = utils::getVals(config::get($rds ?? config::get("global", "defaultRDS")), "host", "port", "password");
        ($this->conn = new Redis())->connect($host, $port);
        
        if ($password) {
            $this->conn->auth($password);
        }
    }
    
    function __destruct() {
        $this->conn->close();
    }
    
    /**
     * @param string $name
     * @param array  $arguments
     * @return mixed
     */
    function __call(string $name, array $arguments) {
        return $this->conn->{$name}(...$arguments);
    }
}